package com.shenmazong.servertalkadmin.controller;

import com.shenmazong.servertalkadmin.service.TbAdminService;
import com.shenmazong.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@CrossOrigin
@Api(tags = "接口-系统用户管理微服务")
public class AdminController {

    @Autowired
    TbAdminService tbAdminService;

    /**
     * TODO addAdminUser 增加管理员用户
     * @return
     */
    @PostMapping(value = "/addAdminUser")
    @ApiOperation(value = "添加管理员", notes = "系统添加管理员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userName", value = "登录账号", dataType = "String", required = true),
            @ApiImplicitParam(name = "userPass", value = "登录密码", dataType = "String", required = true)
    })
    public ResponseResult addAdminUser(@RequestParam("userName") String userName,
                                       @RequestParam("userPass") String userPass) {
        return tbAdminService.addAdminUser(userName, userPass);
    }

    /**
     * TODO delAdminUser 删除管理员
     * @return
     */
    @PostMapping(value = "/delAdminUser")
    @ApiOperation(value = "删除管理员", notes = "删除管理员")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "管理员ID", dataType = "int", required = true, example = "0")
    })
    public ResponseResult delAdminUser(@RequestParam("userId") Integer userId) {
        return tbAdminService.delAdminUser(userId);
    }

    /**
     * TODO 修改管理员密码
     * @return
     */
    @PostMapping(value = "/setAdminPass")
    @ApiOperation(value = "重置管理员密码", notes = "重置管理员密码")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "管理员ID", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "userPass", value = "管理员密码", dataType = "String", required = true, example = "123456")
    })
    public ResponseResult setAdminPass(@RequestParam("userId") Integer userId,
                                       @RequestParam("userPass") String userPass) {
        return tbAdminService.setAdminPass(userId, userPass);
    }

    /**
     * TODO 管理员登录
     * @return
     */
    @PostMapping(value = "/doAdminLogin")
    @ApiOperation(value = "管理员登录", notes = "系统管理员登录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userName", value = "登录账号", dataType = "String", required = true, example = "admin"),
            @ApiImplicitParam(name = "userPass", value = "登录密码", dataType = "String", required = true, example = "123456")
    })
    public ResponseResult doAdminLogin(@RequestParam("userName") String userName,
                                       @RequestParam("userPass") String userPass) {
        return tbAdminService.doAdminLogin(userName, userPass);
    }

    @PostMapping(value = "/getAdminList")
    @ApiOperation(value = "管理员列表", notes = "返回所有管理员的信息")
    public ResponseResult getAdminList() {
        return tbAdminService.getAdminList();
    }
}
